package pl.edu.pjwstk.kor.sbql4j.project1;

import pl.wcislo.sbql4j.db4o.Db4oSBQLQuery;
import com.db4o.*;
import com.db4o.ObjectContainer;

import com.db4o.foundation.*;

import com.db4o.internal.*;
import com.db4o.internal.btree.*;

import org.apache.commons.collections.CollectionUtils;

import pl.edu.pjwstk.kor.database.Database;
import pl.edu.pjwstk.kor.database.Sbql4jQuery;
import pl.edu.pjwstk.kor.model.Customer;
import pl.edu.pjwstk.kor.model.Deal;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Rank;
import pl.edu.pjwstk.kor.model.Service;

import pl.wcislo.sbql4j.exception.*;
import pl.wcislo.sbql4j.java.model.runtime.*;
import pl.wcislo.sbql4j.java.model.runtime.Struct;
import pl.wcislo.sbql4j.java.model.runtime.factory.*;
import pl.wcislo.sbql4j.java.utils.ArrayUtils;
import pl.wcislo.sbql4j.java.utils.OperatorUtils;
import pl.wcislo.sbql4j.java.utils.Pair;
import pl.wcislo.sbql4j.lang.codegen.nostacks.*;
import pl.wcislo.sbql4j.lang.codegen.simple.*;




import pl.wcislo.sbql4j.lang.parser.expression.*;
import pl.wcislo.sbql4j.lang.parser.expression.OrderByParamExpression.SortType;
import pl.wcislo.sbql4j.lang.parser.terminals.*;
import pl.wcislo.sbql4j.lang.parser.terminals.operators.*;
import pl.wcislo.sbql4j.lang.types.*;
import pl.wcislo.sbql4j.lang.xml.*;
import pl.wcislo.sbql4j.model.*;
import pl.wcislo.sbql4j.model.collections.*;
import pl.wcislo.sbql4j.util.*;
import pl.wcislo.sbql4j.util.Utils;
import pl.wcislo.sbql4j.xml.model.*;
import pl.wcislo.sbql4j.xml.parser.store.*;

import java.util.*;
import java.util.Collection;


public class Project1Query_SbqlQuery0Db4o0 implements Db4oSBQLQuery {
    private java.lang.Double serviceCost;

    public Project1Query_SbqlQuery0Db4o0(java.lang.Double serviceCost) {
        this.serviceCost = serviceCost;
    }

    /**
     * query='db.(Service where getMinServiceCost() >= serviceCost)'
    '
     **/
    public java.util.Collection<pl.edu.pjwstk.kor.model.Service> executeQuery(
        final ObjectContainerBase ocb, final Transaction t) {
        final LocalTransaction transLocal = (LocalTransaction) t;
        final java.util.Collection<pl.edu.pjwstk.kor.model.Service> _ident_Service =
            new java.util.ArrayList<pl.edu.pjwstk.kor.model.Service>();
        ClassMetadata _classMeta0 = ocb.classCollection()
                                       .getClassMetadata("pl.edu.pjwstk.kor.model.Service");
        long[] _ids0 = _classMeta0.getIDs(transLocal);

        for (long _id0 : _ids0) {
            LazyObjectReference _ref0 = transLocal.lazyReferenceFor((int) _id0);
            _ident_Service.add((pl.edu.pjwstk.kor.model.Service) _ref0.getObject());
        }

        java.util.Collection<pl.edu.pjwstk.kor.model.Service> _whereResult = new java.util.ArrayList<pl.edu.pjwstk.kor.model.Service>();
        int _whereLoopIndex = 0;

        for (pl.edu.pjwstk.kor.model.Service _whereEl : _ident_Service) {
            if (_whereEl == null) {
                continue;
            }

            if (_whereEl != null) {
                ocb.activate(_whereEl, 1);
            }

            java.lang.Double _mth_getMinServiceCostResult = _whereEl.getMinServiceCost();

            if (_mth_getMinServiceCostResult != null) {
                ocb.activate(_mth_getMinServiceCostResult, 1);
            }

            java.lang.Double _ident_serviceCost = serviceCost;

            Boolean _more_or_equalResult = _mth_getMinServiceCostResult >= _ident_serviceCost;

            if (_more_or_equalResult) {
                _whereResult.add(_whereEl);
            }

            _whereLoopIndex++;
        }

        pl.wcislo.sbql4j.db4o.utils.DerefUtils.activateResult(_whereResult, ocb);

        return _whereResult;
    }
}
